home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pcrob13.zip / EXAMPLES / SIMPLE.PAS < prev   
Pascal/Delphi Source File  |  1992-10-29  |  2KB  |  102 lines

  1. PROGRAM Simple;
  2.  
  3. USES PCRobots;
  4.  
  5. CONST ARENA_WALL=1;
  6.  
  7.  { Define possible angles of motion
  8.  * x,y are x,y positions on the local map
  9.  * angle is the angle of motion to specify
  10.  }
  11.  
  12. CONST
  13.      Angle: ARRAY[1..8] OF
  14.      RECORD
  15.            X    : Integer;
  16.            Y    : Integer;
  17.            Angle: Integer;
  18.      END
  19.           = ((X:5; Y:4; Angle:0),
  20.              (X:5; Y:5; Angle:45),
  21.              (X:4; Y:5; Angle:90),
  22.              (X:3; Y:5; Angle:135),
  23.              (X:3; Y:4; Angle:180),
  24.              (X:3; Y:3; Angle:225),
  25.              (X:4; Y:3; Angle:270),
  26.              (X:5; Y:3; Angle:315));
  27.  
  28.  
  29.  
  30. VAR
  31.     Local_Map   : Map_Buffer;                { Buffer to hold the local map }
  32.     X_Pos, Y_Pos: Integer;                   { Current X and Y coordinates  }
  33.     Go_Dir      : Integer;             { Current direction (index to angle[]) }
  34.     Scan_Angle  : Integer;
  35.     Range       : Integer;
  36.     Try         : Integer;
  37.  
  38.     DummyI      : Integer;
  39.  
  40. BEGIN
  41.  
  42.     { Configure robot - all normal settings in this case            }
  43.     { This *MUST* be the first special function called by the robot }
  44.  
  45.     DummyI := Configure(2,2,2,2,2,0);
  46.  
  47.     Randomize;
  48.     Go_Dir := Random(8) + 1;        { Select initial direction }
  49.  
  50.     WHILE True DO
  51.     BEGIN
  52.         { Get the current position }
  53.         GetXY(X_Pos, Y_Pos);
  54.  
  55.         { Get a map of the local area }
  56.         Get_Local_Map(@Local_Map);
  57.  
  58.         { Quick and easy way of dealing with the }
  59.         { robot being near an outside wall       }
  60.  
  61.         IF X_Pos < 20 THEN
  62.             Go_Dir :=((Random(3)-1) MOD 8) + 1;
  63.  
  64.         IF X_Pos >= 980 THEN
  65.             Go_Dir := random(3)+3;
  66.  
  67.         IF y_pos < 20 THEN
  68.            go_dir := random(3)+1;
  69.  
  70.         IF y_pos >= 980 THEN
  71.            go_dir := random(3)+5;
  72.  
  73.         Try:=0;
  74.  
  75.         { Look for a square which hasn't got a wall in it }
  76.         { (ignore traps in this simple program)           }
  77.         WHILE (local_map[angle[go_dir].y][angle[go_dir].x] = ARENA_WALL)
  78.           AND (Try <= 10) DO
  79.         BEGIN
  80.             go_dir := random(8) + 1;
  81.             Inc(Try);
  82.             SwapTask;
  83.         END;
  84.  
  85.  
  86.         { Move in the new direction }
  87.         Movement(50,angle[go_dir].angle);
  88.  
  89.  
  90.         { Check if target found, shoot at it if so, }
  91.         { otherwise go to next angle                }
  92.  
  93.         IF (scan(scan_angle,5, Range)>=0) THEN
  94.             DummyI := shoot(scan_angle,range)
  95.         else
  96.             scan_angle := (scan_angle+5) MOD 360;
  97.  
  98.     END;
  99.  
  100. END.
  101.   
  102.